package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/access")
public class AccessDataController {

    @GetMapping("/message")
    public void a(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
//        JSONObject jsonObject = new JSONObject();
//        JSONObject json = new JSONObject();
//        JSONObject xinxi = new JSONObject();
//        JSONObject xinxi1 = new JSONObject();
//        JSONObject xinxi2 = new JSONObject();
//        JSONObject xinxi3 = new JSONObject();
//
//        JSONArray Array = new JSONArray();
//        jsonObject.put("instruction","updatepoi");
//        json.put("updatetype","reset");
//        json.put("poigroup","interlocking");
//        json.put("poitype","message");
//
//        xinxi.put("所属区域名称","一号库汽油罐区");
//        xinxi.put("设备名称","T111汽油罐");
//        xinxi.put("指标名称","HV1111出口阀状态");
//        xinxi.put("实时●状态","关");
//        xinxi.put("实时●数值","2.65");
//        xinxi.put("位号","SCADA_D_HY1111");
//
//        xinxi1.put("所属区域名称","一号库汽油罐区");
//        xinxi1.put("设备名称","HV1112进口阀状态");
//        xinxi1.put("指标名称","HV1111出口阀状态");
//        xinxi1.put("实时●状态","关");
//        xinxi1.put("实时●数值","4.97");
//        xinxi1.put("位号","SCADA_D_HY2022");
//
//
//        xinxi2.put("所属区域名称","一号库汽油罐区");
//        xinxi2.put("设备名称","T111汽油罐");
//        xinxi2.put("指标名称","HV1113倒罐阀状态");
//        xinxi2.put("实时●状态","关");
//        xinxi2.put("实时●数值","3.33");
//        xinxi2.put("位号","SCADA_D_HY1113");
//
//        xinxi3.put("所属区域名称","一号库汽油罐区");
//        xinxi3.put("设备名称","T111汽油罐");
//        xinxi3.put("指标名称","XVT111A进料阀关状态");
//        xinxi3.put("实时●状态","关");
//        xinxi3.put("实时●数值","2.40");
//        xinxi3.put("位号","SIS_D_XZSC_T111A");
//
//        Array.add(xinxi);
//        Array.add(xinxi1);
//        Array.add(xinxi2);
//        Array.add(xinxi3);
//        json.put("Array",Array);
//        jsonObject.put("param",json);
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");

        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction","resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        JSONObject jsonObject2 = new JSONObject();
        JSONObject json2 = new JSONObject();
        jsonObject2.put("instruction","showpoi");
        json2.put("showtype","group");
        json2.put("poigroup","menjin");
        json2.put("poitype","menjin");
        jsonObject2.put("param",json2);
        WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//        for (int i = 0; i < 2; i++) {
//            if (i == 0) {
//                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
//            } else {
//                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//            }
//        }
    }
}
